#include "MachineObj.h"
#include "../SGD Wrappers/CSGD_DirectInput.h"
#include "../SGD Wrappers/CSGD_TextureManager.h"
#include "../SGD Wrappers/CSGD_Direct3D.h"
#include "Events/CSGD_EventSystem.h"
#include "Camera.h"


MachineObj::MachineObj(void)
{
	IsBroken = true;

	this->objectID = "Machine";

	RepairedStateImageID = -1;
	BrokenStateImageID = -1;

}


MachineObj::~MachineObj(void)
{
}

void MachineObj::Update(float deltaTime)
{
}
void MachineObj::Render(void) const
{
	GameObject::Render();

	//RECT box = GetHitBox();
	//box.left = (int)(box.left - Camera::GetInstance()->OffsetX());
	//box.right = (int)(box.right - Camera::GetInstance()->OffsetX());
	//box.bottom = (int)(box.bottom - Camera::GetInstance()->OffsetY());
	//box.top = (int)(box.top - Camera::GetInstance()->OffsetY());
	//CSGD_Direct3D::GetInstance()->DrawHollowRect(box,D3DCOLOR_ARGB(255,255,255,0));
}

void MachineObj::HandleCollision(GameObject& other, CollisionInfo& info)
{
	//Check input and set repaired
	if( other.GetObjectID() == "Player" )
	{
		if(CSGD_DirectInput::GetInstance()->KeyPressed( DIK_SPACE ) || CSGD_DirectInput::GetInstance()->JoystickButtonPressed(3))
		{
			SetState( false );
		}
	}
}

bool MachineObj::GetIsBroken()
{
	return this->IsBroken;
}

void MachineObj::RepairMachine()
{
	this->IsBroken = false;
}

void MachineObj::SetState(bool Broken)
{
	IsBroken = Broken;
	if( IsBroken == true )
	{
		imageID = BrokenStateImageID;
	}
	else
	{
		imageID = RepairedStateImageID;
		CSGD_EventSystem::GetInstance()->SendEvent("MachineFixed", NULL, NULL, (void*)this );
	}
}

void MachineObj::SetRepairedImageID( int index )
{
	this->RepairedStateImageID = index;
}

void MachineObj::SetBrokenImageID( int index )
{
	this->BrokenStateImageID = index;
	this->imageID = BrokenStateImageID;
}